/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2021/11/1
 * Time: 8:54
 * Description:
 */
//非受查异常-运行时异常
class MyException1 extends RuntimeException{
    public MyException1(String msg) {
        super(msg);
    }
}
//受查异常-编译时异常
class MyException extends Exception{
    public MyException(String msg) {
        super(msg);
    }
}

class UserException extends Exception {
    public UserException(String message) {
        super(message);
    }
}
class PasswordException extends Exception {
    public PasswordException(String message) {
        super(message);
    }
}

//fn+esc
public class TestDemo {

    private static String userName = "admin";
    private static String password = "123456";

    public static void main(String[] args) {
        try {
            login("admin9", "123456");
        } catch (UserException userError) {
            userError.printStackTrace();
        } catch (PasswordException passwordError) {
            passwordError.printStackTrace();
        }
    }
    public static void login(String userName, String password) throws UserException,
            PasswordException {
        if (!TestDemo.userName.equals(userName)) {
            throw new UserException("用户名错误");
        }
        if (!TestDemo.password.equals(password)) {
            throw new PasswordException("密码错误");
        }
        System.out.println("登陆成功");
    }

    public static void main3(String[] args){
        int a = 10;
        try {
            if(a == 10) {
                throw new MyException("haha");
            }
        }catch (MyException e) {

        }

    }

    public static void divi(int x) throws ArithmeticException{
        if(x == 0) {
            throw new ArithmeticException("x==0");
        }
    }

    public static void main1(String[] args) {
        try {
            divi(0);
        }catch (ArithmeticException e) {
            e.printStackTrace();
        }
    }
}
